const state = {
  isConnected: false, //连接状态
  webSocketMsg: "",
};
const getters = {};
const mutations = {
  setConnected(state: any, isConnected: boolean) {
    console.log("isConnected: ", isConnected);
    state.isConnected = isConnected;
  },
  SET_WS_MSG(state: any, msg: any) {
    state.webSocketMsg = msg;
  },
};
const actions = {
  connect({ commit }: { commit: any }) {
    // 连接成功后，将 isConnected 状态设置为 true
    commit("setConnected", true);
  },
  disconnect({ commit }: { commit: any }) {
    // 断开连接或退出登录时，将 isConnected 状态设置为 false
    commit("setConnected", false);
  },
};
export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};

// computed:{
//     getWsMsg (){
//         return this.$store.state.webSocketMsg
//     }
// },
// watch:{
//     getWsMsg:{
//         handler: function(newVal) {
//             console.log(newVal)
//             alert('接收到webSocket推送'+ newVal)
//         }
//     }
// }
